package com.cloud.rou.im.client.statemachine;

import lombok.AllArgsConstructor;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 */
@AllArgsConstructor
public class Transition {

    private MsgState toState;

    private MsgListener<StateMachineContext> action;

    public MsgState getToState() {
        return toState;
    }

    public void action(StateMachineContext context) {
        if (null != action) {
            action.listen(context);
        }
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        private MsgState toState;

        private MsgListener<StateMachineContext> action;

        public Builder toStateAndAction(MsgState state, MsgListener<StateMachineContext> action) {
            this.toState = state;
            this.action = action;
            return this;
        }


        public Transition build() {
            return new Transition(toState, action);
        }
    }

}
